 ///////////////////////////////
//	File:		GamePlayState.h
//	Class:		SGP
//	Updated:	3/8/2012
//	Author:		Roc Myers
///////////////////////////////
#pragma once

#include "GameState.h"
#include "MainMenuState.h"
#include "Game.h"
#include "BaseCharacter.h"
#include "BitmapFont.h"
#include "BaseMessage.h"
#include "MessagingSystem.h"
#include "TileManager.h"
#include "Animation.h"
#include "AnimationManager.h"
#include "Archer.h"
#include "Knight.h"
#include "Rogue.h"
#include "Wizard.h"
#include "BlackKnight.h"
#include "Item.h"
#include "WeatherSystem.h"
#include "AIManager.h"

// Wrappers
#include "SGD Wrappers\CSGD_XAudio2.h"
#include "SGD Wrappers\CSGD_TextureManager.h"

// Unicode 
#include <string>
#if defined UNICODE || _UNICODE
	typedef std::wstring STRING;
#else
	typedef std::string		STRING;
#endif

class GamePlayState : public GameState
{
	// SINGLETON Stuff
	GamePlayState(void);
	GamePlayState(const GamePlayState&);
	GamePlayState& operator=(const GamePlayState&);
	~GamePlayState(void);

	// Asset IDs
	int	BGMID;
	int ShopBGM;
	int FontID;
	int CursorID;
	int tileBmpID;
	int PanelID;
	int selectID;
	int BackgroundID;

	// Map selection
	bool InProgress;
	int MapID;

	// For doing menu & input stuff
	bool Paused;
	bool StartGame;
	int StartChoice;
	bool Resume;
	bool Movement;
	bool Save;
	bool Load;
	bool LoadFailed;
	bool Command;
	bool ItemMenu;
	bool ShopMenu;
	bool StatsMenu;
	bool ArchEquip;
	bool KnEquip;
	bool WizEquip;
	bool RgEquip;
	bool Items;
	bool Equip;
	bool Chars;
	bool RWpn;
	bool RArm;
	bool KWpn;
	bool KArm;
	bool AWpn;
	bool AArm;
	bool WWpn;
	bool WArm;
	bool tutStart;
	int tutChoice;
	int CmndChoice;
	int ItemChoice;
	int ShopChoice;
	bool Attack;
	bool gameWon;
	float gameWonTimer;
	bool gameWon2;
	int File;
	bool DiceRolled;
	bool DiceShown;
	float DiceTime1;
	float DiceTime2;
	float DShownTime;
	RECT diceRECT;
	bool abilityMenu;
	int abilitySelection;
	bool abilityTargeting;
	bool playerTurn;
	bool SelectingaTile;
	int SelectingCount;
	int SizeOfParty;
	int Gold;
	bool gameLost;
	int ShopBmp;
	float scaleInc;
	int declineID;
	int acceptID;
	int errorID;
	int moveID;
	int blankRectID;
	int sunnyID;
	int	twentyID;
	int drinkID;
	int	inhalerID;
	int	TennisballID;
	int PlungerID;
	int fireCrackerID;
	int WaterBalloonID;
	int reinforceID;
	int	gotchaID;
	int	hideID;
	int	healID;
	int chickenID;
	int	pansyID;
	int drawID;
	int biteID;
	int noneID;
	int imID;
	int woundID;
	int allergyID;
	int twentyBMPID;
	int boltID;
	int fireID;
	int waterID;
	int boingID;
	int thudID;
	int swingID;
	int throwID;
	int splashID;
	int crackerID;
	int tennisID;
	int rhurtID;
	int whurtID;
	int khurtID;
	int ahurtID;
	bool Throw;
	bool SpellHit;
	bool playVoice;
	bool fbHurt;
	bool multishotbullshitfix;

	bool  twentyRender;
	float twentyTimer;
	int twentyPosX;

	bool aiTargeting;
	BaseCharacter * aiTarget;
	BaseCharacter * aiSelected;

	// variables for pre battle character selection
	int preLeftSelection;
	int preRightSelection;
	bool prebattle;
	vector<BaseCharacter*> selectFrom;
	vector<BaseCharacter*> selected;
	bool leftSideSelecting;

	//DiceRoll Vectors
	vector<int> AtkRolls;
	vector<int> DefRolls;
	vector<int> ARolls;
	vector<int> DRolls;
	vector<int> DiceImages;

	// Temporary stats for level-up screen display purposes
	int tempAtk;
	int tempStm;
	int tempDef;
	int tempAgi;
	int tempSpd;
	int tempHP;
	int tempMP;
	unsigned int tempLvl;

	bool actionWindow;
	bool actionWindowTimed;
	float actionWindowTimer;
	int actionWindowEnum;

	// Message System
	MessagingSystem* MS;

	// Bitmap Font
	CBitmapFont Font;

	// Character Related Variables
	vector<BaseCharacter*> Characters;
	vector<Item*> Inventory;
	int HPotions;
	int MPotions;
	int Inhalers;
	float Timer;
	bool Turn;
	bool ShowTurn;
	BaseCharacter* Viewing;
	vector<BaseCharacter*> CharactersToTake;
	vector<Item*> enemyInventory;

	// tile manager
	TileManager * gameGrid;
	Tile * activeTile;

	//stuff for particle
	vector<string> AllKeys;
	vector<string> ActiveKeys;
	int WeatherTime;
	int WeatherRand;
	int WeatherType;
	int RainSound;
	int SnowSound;

	//camera
	bool cursorMoved;
	bool AImoving;

	//Battle Window Stuff
	RECT FadeWindow;
	int FadeWindowImg;
	void BattleWindowFade(void);
	void BattleWindow();
	BaseCharacter* CurAttacker;
	BaseCharacter* CurDefender;
	int Explosion;
	float Modifier;
	int AtkTypeStorage;
	float Shotspeed;
	float Shotspeed2;

	// SINGLETON
	static GamePlayState* pInstance;

	// Animation Manager
	AnimationManager* myManager;

	// position of cursor (in tile index space)
	int cursorX;
	int cursorY;

	//ai manager
	AIManager * ai;

	// map selection
	int mapSelection;
	int mapToUse;
	bool mapSelectBool;

	// map progression bools
	bool map2Unlocked;
	bool map3Unlocked;

	// arcade input bools
	bool arcadeEnter;
	bool arcadeEscape;
	bool arcadeUp;
	bool arcadeDown;
	bool arcadeLeft;
	bool arcadeRight;
	bool arcadeBackspace;
	bool arcadeShift;
	bool arcadePlus;
	bool arcadeMinus;
	bool arcadeP;

	// input and render functions
	void MapSelectInput();
	void MapSelectRender();
	void LoadInput();
	void LoadRender();
	void TutorialInput();
	void TutorialRender();
	void ShopInput();
	void ShopRender();
	void SaveInput();
	void SaveRender();
	void PrebattleInput();
	void PrebattleRender();
	void GameInput();
	void GameRender();


public:
	static GamePlayState* GetInstance(void);
	void DeleteInstance();

	int kdeathID;
	int rdeathID;
	int wdeathID;
	int adeathID;

	// Inherited Functionality
	void Enter(void);	
	bool Input(void);	
	void Update(float fElapsedTime);	
	void Render(void);	
	void Exit(void);

	// Buy An Item
	void ItemPurchased(Item* i);

	//Attack/Defend Roll
	int DiceRoll(BaseCharacter* Attacker, BaseCharacter* Defender,int wizzardEnum = -1);
	void SetAtkTypeStorage(int number) { AtkTypeStorage = number; }

	//Dice Render
	void RenderDice();
	void RenderRoll();

	//Dice Cell calculation
	RECT DiceCell(int X, int Y);

	//WeatherRandom
	void ChoseWeather();

	//Adding to ActiveParticles
	void AddToActive(string Particle);

	//Getting Damage for Rendering
	int TotalDamage;

	int GetDamage(void)				{ return TotalDamage; }
	void SetDamage(int totaldamage) { TotalDamage = totaldamage; }

	//Getting Healing for Rendering
	int TotalHealing;
	float healingTimer;
	bool healingShit;

	int GetHealing(void)			{return TotalHealing; }
	void SetHealing(int healing)	{ TotalHealing = healing; }
	void PotRender(void);

	// Message Procedure
	static void MessageProc(BaseMessage* pMsg);

	// Save Data
	void SaveGame(Tile * curTile, vector<BaseCharacter*>charList, int fileNumber);

	// Load Data
	bool LoadSave(int fileNumber);

	int GetCursorX()
	{
		return cursorX;
	}

	int GetCursorY()
	{
		return cursorY;
	}

	bool * GetPlayerBool()
	{
		return &this->playerTurn;
	}

	bool GetDiceRolled(void)			 {return DiceRolled;}
	bool GetDiceShown(void)				 {return DiceShown;}
	vector<int> GetARolls(void)			 {return ARolls;}
	vector<int> GetDRolls(void)			 {return DRolls;}
	vector<int> GetAtkRolls(void)		 {return AtkRolls;}
	vector<int> GetDefRolls(void)		 {return DefRolls;}
	float GetDiceTime1(void)			 {return DiceTime1;}
	float GetDiceTime2(void)			 {return DiceTime2;}
	float GetDShownTime(void)			 {return DShownTime;}
	Tile* GetActiveTile(void)			 {return activeTile;}
	float GetModifier(void)				 {return Modifier; }
	vector<string>	GetActiveKeys(void)	 {return ActiveKeys; }


	void SetModifier(float Mod)					{Modifier = Mod;}
	void SetActiveTile(Tile* AT)				{activeTile = AT;}
	void SetDiceRolled(bool val)				{DiceRolled = val;}
	void SetDiceShown(bool val)					{DiceShown = val;}
	void SetDiceID(vector<int> val)				{DiceImages = val;}
	void SetDiceTime1(float val)				{DiceTime1 = val;}
	void SetDiceTime2(float val)				{DiceTime2 = val;}
	void SetDShownTime(float val)				{DShownTime = val;}
	void SetFontID(int val)						{FontID = val;}
	int GetWeatherTime(void)					{return WeatherTime;}
	void SetWeatherTime(int weathertime)		{ WeatherTime = weathertime;}
	void SetFont(CBitmapFont val)				{Font = val;}
	void SetFadeWindowImage(int img)			{FadeWindowImg = img;}
	void SetFadeWindow(RECT window)				{FadeWindow = window;}
	void SetCurAttacker(BaseCharacter* pBase)	{CurAttacker = pBase;}
	void SetCurDefender(BaseCharacter* pBase)	{CurDefender = pBase;}
	void SetAniManager(AnimationManager* pAni)	{myManager = pAni;}
	void SetExplosionImg(int img)				{Explosion = img;}
	void SetLBoltImg(int img)					{TennisballID = img;}
	void SetAtckSound(int sound)				{swingID = sound;}
	void SetHitSound(int sound)					{thudID = sound;}
	void SetSwingSound(int sound)				{swingID = sound;}
	void SetLBoltSound(int sound)				{boltID = sound;}
	void SetLBoltHit(int sound)					{tennisID = sound;}
	void SetThrowID(int sound)					{throwID = sound;}
	void SetShotSpeed(float SS)					{Shotspeed = SS;}
	void SetKhurtId(int Khurt)					{khurtID = Khurt;}
	void SetPlayVoice(bool voice)				{playVoice = voice;}
	void SetBoltID(int boldsoundzz)				{boltID = boldsoundzz;}
	void SetSpellHit(bool SH)					{SpellHit = SH; }
	void SetThrownSound(bool TS)				{Throw = TS; }
	void SetCursorMoved(bool moved)				{cursorMoved = moved;}
	void SetAImoving(bool moving)				{AImoving = moving;}

	vector<BaseCharacter*> * GetCharacters()
	{
		return &this->Characters;
	}

	vector<Item*> * GetEnemyInventory()
	{
		return &enemyInventory;
	}

	void EquipItem(Item * item);

	void LoadEquipment();

	int GetBlankRect() {return this->blankRectID;}
	
	void HighlightMove();

	void HighlightAction(bool enemy,int range);

	void ChangeTurnBool() {Turn = !Turn; ShowTurn = true;}

	void ArcadeInput();

	void SetAITargeting(bool b)
	{
		aiTargeting = b;
	}

	void SetAICharacters(BaseCharacter* target,BaseCharacter* selected)
	{
		this->aiTarget = target;
		this->aiSelected = selected;
	}

	int GetHealID(void)			const	{ return healID; }
	int GetGotchaID(void)		const	{ return gotchaID; }
	int	GetHideID(void)			const	{ return hideID; }
	int GetDrinkID(void)		const	{ return drinkID; }
	int GetInhalerID(void)		const	{ return inhalerID; }
	int GetReinforceID(void)	const	{ return reinforceID; }
	int GetWoundID(void)		const	{ return woundID; }
	int GetChickenID(void)		const	{ return chickenID; }
	int GetPansyID(void)		const	{ return pansyID; }
	int GetDrawID(void)			const	{ return drawID; }
	int GetBiteID(void)			const	{ return biteID; }
	int GetNoneID(void)			const	{ return noneID; }
	int GetImID(void)			const	{ return imID; }
	int GetAllergyID(void)		const	{ return allergyID; }

	void StartActionWindow(int i);

	bool CheckMoveToTile(Tile* curTile, Tile* tar, vector<Tile*>* v = nullptr);

	void ClearDiceVectors(void);

};

